<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>作业与考试 - 学习资源平台</title>
    <link rel="stylesheet" th:href="@{/css/common.css}">
    <link rel="stylesheet" th:href="@{/css/navbar.css}">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="stylesheet" th:href="@{/css/assignmentlist.css}">
</head>
<body>
<div class="container">
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg">
        <div class="container">
            <a class="navbar-brand" href="#">云学堂</a>
            <div class="collapse navbar-collapse">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/resource/list}">学习资源</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" th:href="@{/assignment/list}">作业与考试</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/forum/list}">交流互动</a>
                    </li>
                    <li class="nav-item" th:if="${session.identity=='superAdmin' || session.identity=='ordinaryAdmin'}">
                        <a class="nav-link" th:href="@{/admin/index}">管理中心</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/user/digital}">个人中心</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/user/logout}">退出</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <div class="row mt-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h2>作业列表</h2>
                <a th:href="@{/assignment/publish}" class="btn btn-primary">发布作业</a>
            </div>

            <!-- 作业列表 -->
            <div class="row">
                <div class="col-12">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>作业标题</th>
                                    <th>所属专业</th>
                                    <th>截止时间</th>
                                    <th>发布者</th>
                                    <th>状态</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="assignment : ${assignmentList}">
                                    <td th:text="${assignment.title}">作业标题</td>
                                    <td>
                                        <span th:if="${assignment.majorId != null}" th:text="${assignment.majorId}">专业ID</span>
                                    </td>
                                    <td th:text="${#temporals.format(assignment.deadline, 'yyyy-MM-dd HH:mm')}">截止时间</td>
                                    <td>
                                        <span th:if="${assignment.uploaderId != null}" th:text="${assignment.uploaderId}">发布者ID</span>
                                    </td>
                                    <td>
                                        <span th:if="${assignment.status == 1}" class="text-success">进行中</span>
                                        <span th:if="${assignment.status == 0}" class="text-secondary">已结束</span>
                                    </td>
                                    <td th:text="${#temporals.format(assignment.createdTime, 'yyyy-MM-dd HH:mm')}">发布时间</td>
                                    <td>
                                        <a th:href="@{'/assignment/' + ${assignment.id}}" class="btn btn-sm btn-info">查看</a>
                                        <a th:href="@{'/assignment/submit/' + ${assignment.id}}" class="btn btn-sm btn-primary">提交</a>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <!-- 分页 -->
                    <nav aria-label="Page navigation">
                        <ul class="pagination justify-content-center">
                            <li class="page-item" th:classappend="${page.current <= 1} ? 'disabled'">
                                <a class="page-link" 
                                   th:href="@{/assignment/list(page=${page.current - 1}, size=${page.size})}">上一页</a>
                            </li>
                            
                            <li class="page-item" th:each="i : ${#numbers.sequence(1, page.pages)}" 
                                th:classappend="${i == page.current} ? 'active'">
                                <a class="page-link" 
                                   th:href="@{/assignment/list(page=${i}, size=${page.size})}" 
                                   th:text="${i}">1</a>
                            </li>
                            
                            <li class="page-item" th:classappend="${page.current >= page.pages} ? 'disabled'">
                                <a class="page-link" 
                                   th:href="@{/assignment/list(page=${page.current + 1}, size=${page.size})}">下一页</a>
                            </li>
                        </ul>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>